home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT1-5 / RDNUM.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-08-27  |  1.5 KB  |  36 lines

  1. ;
  2. ;       Program RdNum ( Chapter 1 )
  3. ;
  4. .model  small
  5. .stack
  6. .data
  7. UnsWord dw      0
  8. Hex     dw      16
  9. .code
  10. .startup
  11. NextCh: mov     ah,01           ; function 01h - keyboard input
  12.     int     21h             ; DOS service call
  13.     cmp     al,0            ; special character?
  14.     jne     NotSpec         ; if not - process character
  15.     int     21h             ; read code of special character
  16.     jmp     FinProg         ; finish program
  17. NotSpec:cmp     al,'0'          ; compare character read to "0" (number?)
  18.     jb      FinProg         ; if not, don't process
  19.     cmp     al,'9'          ; compare character read to "9" (number?)
  20.     jbe     ProcNum         ; if numeric - process
  21.     cmp     al,'A'          ; compare character read to "A" (hex number?)
  22.     jb      FinProg         ; if not, don't process
  23.     cmp     al,'F'          ; compare character read to "F" (hex number?)
  24.     ja      FinProg         ; if not, don't process
  25.     sub     al,7            ; prepare characters A - F for converting
  26. ProcNum:sub     al,30h          ; convert character to number
  27.     mov     bl,al           ; copy character read into BX
  28.     mov     ax,UnsWord      ; hex number into AX
  29.     mul     Hex             ; one hex position to the left
  30.     mov     UnsWord,ax      ; store result back into memory
  31.     add     UnsWord,bx      ; add current hex digit
  32.     jmp     NextCh          ; read next character
  33. FinProg:mov     ax,4C00h        ; function 4Ch - terminate process
  34.     int     21h             ; DOS service call
  35.     end     
  36.